package com.example.mybatispermission.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.mybatispermission.entry.Permission;
import com.example.mybatispermission.entry.Role;
import com.example.mybatispermission.entry.User;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface PermissionMapper extends BaseMapper<Permission> {
    @Select("select distinct p.* from permission p left join role_permission rp on p.id=rp.pid left join user_role ur on rp.oid=ur.oid where ur.uid=#{user.id}")
    List<Permission> getPermissionsByUser(@Param("user")User user);
    @Select("select distinct p.* from permission p left join role_permission rp on p.id=rp.pid where rp.oid=#{role.id}")
    List<Permission> getPermissionsByRole(@Param("role") Role role);
}
